package dtos

import (
	"strconv"

	"github.com/beego/beego/v2/core/validation"
)

type SendFreeCallsParams struct {
	UserId    int64
	UserIdStr string `json:"user_id"`
	Num       int    `json:"num"`
}

func (sfcp *SendFreeCallsParams) Valid(v *validation.Validation) {
	// 验证UserId是否合法
	var err error
	sfcp.UserId, err = strconv.ParseInt(sfcp.UserIdStr, 10, 64)

	if err != nil {
		_ = v.SetError("user_id", "用户编号不合法")
		return
	}

	if sfcp.Num <= 0 {
		v.SetError("num", "拨打用户编号不合法")
	}

	return
}

type CountFreeCallsParams struct {
	UserId    int64
	UserIdStr string `json:"user_id"`
}
type CountFreeCallsRes struct {
	Num int64 `json:"num"`
}

func (cfcp *CountFreeCallsParams) Valid(v *validation.Validation) {
	// 验证UserId是否合法
	var err error
	cfcp.UserId, err = strconv.ParseInt(cfcp.UserIdStr, 10, 64)

	if err != nil {
		_ = v.SetError("user_id", "用户编号不合法")
		return
	}

	return
}
